package com.lagou.task15;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

public class HashSetTest {
    public static void main(String[] args) {
        //set集合不予许重复
        Set<String> s1 = new HashSet<>();
        System.out.println("s1 = " + s1);
        System.out.println("------------------------");
        s1.add("two");
        s1.add("three");
        s1.add("one");
        System.out.println("s1 = " + s1);
        s1.add("one");
        s1.add("add");
        //元素没有放入顺序
        System.out.println("s1 = " + s1);//[add, one, two, three]
        System.out.println("------------------------");
        Set<String> s2 = new LinkedHashSet<>();
        System.out.println("s1 = " + s1);
        System.out.println("------------------------");
        s2.add("two");
        s2.add("three");
        s2.add("one");
        System.out.println("s1 = " + s2);
        s2.add("one");
        s2.add("add");
        //LinkedHashSet有放入顺序
        System.out.println("s1 = " + s2);//[add, one, two, three]

    }
}
